home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Compilers / Miracle C Compiler / miricleC compiler.msi / Instal01.cab / _4F7C91D2FABF436F8E0B30924C0D6D02 < prev    next >
Encoding:
Text File  |  2000-07-31  |  1.2 KB  |  78 lines

  1. #include <stdio.h>
  2. #include <system.h>
  3. #include <io.h>
  4.  
  5.  
  6.  
  7. void f1(), f2();
  8. void seektest();
  9.  
  10. int main(int argc, char **argv)
  11. {
  12.    int i;
  13.  
  14.    for(i=0; i<argc; i++)
  15.       printf("%d %s; ",i,argv[i]);
  16.  
  17.    f1();    f2();
  18.    seektest();
  19. }
  20.  
  21.  
  22. void f1()
  23. {
  24.    int ifile, ofile, bytes;
  25.    char mybuf[110];
  26.  
  27.    ifile= open("grammar",O_RDONLY);
  28.    if(ifile == -1) { printf("bad ifile\n"); exit(0); }
  29.  
  30.    ofile= creat("newfile.txt");
  31.    if(ofile == -1) { printf("bad ofile\n"); exit(0); }
  32.  
  33.    while((bytes=read(ifile,mybuf,100)) > 0)
  34.       {
  35.       write(ofile,mybuf,bytes);
  36.       }
  37.  
  38.    close(ifile);
  39.    return;
  40. }
  41.  
  42.  
  43. void f2()
  44. {
  45.    FILE *fin, *fout;
  46.    char mybuf[110];
  47.  
  48.    fin=fopen("grammar","r");
  49.    fout=fopen("newfile.txt","a");
  50.  
  51.    if(fin==NULL || fout==NULL) { printf("f2 bad file\n"); exit(0); }
  52.  
  53.    fgets(mybuf,100,fin);
  54.  
  55.    while(!feof(fin))
  56.       {
  57.       fputs(mybuf,fout);
  58.       fgets(mybuf,100,fin);
  59.       }
  60.  
  61.    fclose(fin); fclose(fout);
  62.    return;
  63. }
  64.  
  65. char mybuf2[64];
  66.  
  67.  
  68. void seektest()
  69. {
  70.     int h;
  71.     long ls;
  72.  
  73.     h = open("filetwo.c", O_RDONLY);
  74.     ls = lseek( h, 0L, SEEK_END );
  75.     printf( "seekend=%ld\n", ls);
  76.     close(h);
  77. }
  78.